#include <iostream>
using namespace std;

const int N = 2e5 + 10;

int n;
int a[N];

int dfs(int left, int right)
{
	if (left == right)	return a[left];

	int mid = (left + right) >> 1;
	int ret = max(dfs(left, mid), dfs(mid + 1, right));

	int suml = a[mid], sumr = a[mid + 1];
	int maxl = suml, maxr = sumr;

	for (int i = mid - 1; i >= left; i--)
	{
		suml += a[i];
		maxl = max(maxl, suml);
	}

	for (int i = mid + 2; i <= right; i++)
	{
		sumr += a[i];
		maxr = max(maxr, sumr);
	}

	return max((maxl + maxr), ret);
}

int main()
{
	cin >> n;

	for (int i = 1; i <= n; i++)	cin >> a[i];

	cout << dfs(1, n) << endl;

	return 0;
}